package cn.com.web.Servlet;

import cn.com.domain.Customer;
import cn.com.domain.Order;
import cn.com.service.CustomerService;
import cn.com.service.OrderService;
import cn.com.service.impl.CustomerServiceImpl;
import cn.com.service.impl.OrderServiceImpl;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

@WebServlet("/FindCustomerOrderRoomServlet")
public class FindCustomerOrderRoomServlet extends HttpServlet {
    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        String identity_num = request.getParameter("identity_num");
        String phone = request.getParameter("phone");
        CustomerService customerService=new CustomerServiceImpl();
        Customer customer = customerService
                .findcustomerByidentity_numandphone(identity_num, phone);
        //查不到用户直接返回
        if (customer == null){
            request.getRequestDispatcher("showfoundcustomer.jsp").forward(request,response);
            return;
        }
        OrderService orderService=new OrderServiceImpl();
        Order order = orderService.findOrderbycustomer_name(customer.getCustomer_name());
        request.setAttribute("order",order);
        request.getRequestDispatcher("showfoundcustomer.jsp").forward(request,response);
    }

    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        this.doPost(request, response);
    }
}
